#include <string.h>
#include "sipsiparser.h"
#include "builderplugin.h"
#include "dvbplugin_tfdtmb.h"
#include "plugindvbfun.h"
#include "pluginmanual.h"
#include "pluginfull.h"

#define PLUGIN_MONITOR_PERIOD	10000 //10s

#define PLUGIN_TFDTMB_SERVICE_ORDER_TAG 0x88

typedef enum
{
	BUILDER_PLUGIN_IDLE,
	BUILDER_PLUGIN_INPROCESS,
}BUILDER_PLUGIN_STATUS_T;

typedef struct
{
	BUILDER_PLUGIN_STATUS_T		m_eStatus;
	BUILDER_SEARCH_TYPE_T		m_eSearchType;
	unsigned int 					m_u32Process;
}builder_plugin_control_t;

builder_plugin_control_t stBuilderCtrl;

int PluginGetConfig(builder_plugin_cfg_t* pstConfig)
{
	int s32Ret = -1;
	
	PluginDvbLogcat("PluginGetUpdateConfig() - entry, peConfig = %p\r\n", pstConfig);
	if(pstConfig)
	{
		pstConfig->m_eUpdate	 = BUILDER_PROGRAM_UPDATE_NIT_CHANGLE_NEW_SEARCH|BUILDER_PROGRAM_UPDATE_BACKGROUND_AND_NOTIFY;
		pstConfig->m_eSearchType = BUILDER_SEARCH_WITH_MANUL|BUILDER_SEARCH_WITH_AUTO|BUILDER_SEARCH_WITH_QUICK;
		pstConfig->m_eChannelChangeType = BUILDER_PROGRAM_CHANGE_IN_TURN;
		pstConfig->m_eChannelShowType	= BUILDER_PROGRAM_SHOW_INDEX;
		pstConfig->m_u32MonitorPeriod	= PLUGIN_MONITOR_PERIOD;
		pstConfig->m_u8MonitorSwitch	= 0;
		s32Ret = 0;
	}
	PluginDvbLogcat("PluginGetUpdateConfig() - return, s32Ret = %d\r\n", s32Ret);
	return s32Ret;
}

int PluginSearchStart(builder_plugin_search_param_t* pstParam)
{
	int s32Ret = -1;
	
	PluginDvbLogcat("PluginSearchStart() - entry, pstParam = %p\r\n", pstParam);
	if(pstParam)
	{
		if(stBuilderCtrl.m_eStatus == BUILDER_PLUGIN_IDLE)
		{
			s32Ret = 0;
			stBuilderCtrl.m_eSearchType = pstParam->m_eSearchType;
			stBuilderCtrl.m_u32Process = 0;
			switch(pstParam->m_eSearchType)
			{
				case BUILDER_SEARCH_MANUAL_SEARCH:
				{
					s32Ret = PluginManaulSearchStart(&pstParam->m_uParam.m_stManualSearchParam);
					if(s32Ret == 0)
					{
						stBuilderCtrl.m_eStatus = BUILDER_PLUGIN_INPROCESS;
					}
					else
					{
						PluginDvbLogcat("PluginSearchStart() - PluginManaulSearchStart error s32Ret = %d\r\n", s32Ret);
					}
					break;
				}
				case BUILDER_SEARCH_FULL_SEARCH:
				{
					s32Ret = PluginFullSearchStart(&pstParam->m_uParam.m_stAllSearchParam);
					if(s32Ret == 0)
					{
						stBuilderCtrl.m_eStatus = BUILDER_PLUGIN_INPROCESS;
					}
					else
					{
						PluginDvbLogcat("PluginSearchStart() - PluginFullSearchStart error s32Ret = %d\r\n", s32Ret);
					}

					break;
				}
				case BUILDER_SEARCH_AUTO_SEARCH:
				{
					s32Ret = PluginAutoSearchStart();
					if(s32Ret == 0)
					{
						stBuilderCtrl.m_eStatus = BUILDER_PLUGIN_INPROCESS;
					}
					else
					{
						PluginDvbLogcat("PluginSearchStart() - PluginAutoSearchStart error s32Ret = %d\r\n", s32Ret);
					}

					break;
				}

				default:
				{
					PluginDvbLogcat("PluginSearchStart() - not support search type %d\r\n", pstParam->m_eSearchType);
					break;
				}
			}
		}
		else
		{
			PluginDvbLogcat("PluginSearchStart() - receive start msg when status is not idle\r\n");
		}
	}
	PluginDvbLogcat("PluginSearchStart() - return, s32Ret = %d\r\n", s32Ret);
	return s32Ret;	
}


int PluginStatusReset()
{
	int s32Ret = -1;
	
	PluginDvbLogcat("PluginStatusReset() - entry\r\n");
	if(stBuilderCtrl.m_eStatus != BUILDER_PLUGIN_IDLE)
	{
		switch(stBuilderCtrl.m_eSearchType)
		{
			case BUILDER_SEARCH_MANUAL_SEARCH:
			{
				s32Ret = PluginManualSearchReset();
				break;
			}
			case BUILDER_SEARCH_FULL_SEARCH:
			{
				s32Ret = PluginFullSearchReset();
				break;
			}
			case BUILDER_SEARCH_AUTO_SEARCH:
			{
				s32Ret = PluginAutoSearchReset();
				break;
			}
			default:
			{
				PluginDvbLogcat("PluginStatusReset() - error type\r\n");
				break;
			}
		}
	}
	PluginDvbLogcat("PluginStatusReset() - return, s32Ret = %d\r\n", s32Ret);
	
	return s32Ret;		
}

int PluginSearchStop()
{
	int s32Ret = -1;
	
	PluginDvbLogcat("PluginSearchStop() - entry\r\n");
	s32Ret = PluginStatusReset();
	stBuilderCtrl.m_eStatus = BUILDER_PLUGIN_IDLE;
	PluginDvbLogcat("PluginSearchStop() - return, s32Ret = %d\r\n", s32Ret);
	
	return s32Ret;	
}

int PluginLockFinish(builder_tuner_t* pstTunerInfo, unsigned int u32Lock)
{
	int s32Ret = -1;
	
	PluginDvbLogcat("PluginLockFinish() - entry\r\n");
	if(pstTunerInfo)
	{
		PluginDvbLogcat("PluginLockFinish() - stBuilderCtrl.m_eStatus = %d\r\n",stBuilderCtrl.m_eStatus);
		if(stBuilderCtrl.m_eStatus == BUILDER_PLUGIN_INPROCESS)
		{
			s32Ret = 0;
			switch(stBuilderCtrl.m_eSearchType)
			{
				case BUILDER_SEARCH_MANUAL_SEARCH:
				{
					s32Ret = PluginManualSearchLockFinish(pstTunerInfo, u32Lock);
					break;
				}
				case BUILDER_SEARCH_FULL_SEARCH:
				{
					s32Ret = PluginFullSearchLockFinish(pstTunerInfo, u32Lock);
					break;
				}
				case BUILDER_SEARCH_AUTO_SEARCH:
				{
					s32Ret = PluginAutoSearchLockFinish(pstTunerInfo, u32Lock);
					break;
				}
				default:
				{
					PluginDvbLogcat("PluginLockFinish() - error search type, something wrong\r\n");
					break;
				}
			}
		}
	}
	PluginDvbLogcat("PluginLockFinish() - return, s32Ret = %d\r\n", s32Ret);
	return s32Ret;	
}

int PluginGetProcess(unsigned int* pu32DataOk, unsigned int* pu32Process)
{
	int s32Ret = -1;
	
	PluginDvbLogcat("PluginGetProcess() - entry, pu32DataOk = %p, pu32Process = %p\r\n", pu32DataOk, pu32Process);
	if(pu32DataOk && pu32Process)
	{
		switch(stBuilderCtrl.m_eSearchType)
		{
			case BUILDER_SEARCH_MANUAL_SEARCH:
			{
				s32Ret = PluginManualGetProcess(pu32DataOk, pu32Process);
				stBuilderCtrl.m_u32Process = *pu32Process;
				break;
			}
			case BUILDER_SEARCH_FULL_SEARCH:
			{
				s32Ret = PluginFullGetProcess(pu32DataOk, pu32Process);
				stBuilderCtrl.m_u32Process = *pu32Process;
				break;
			}
			case BUILDER_SEARCH_AUTO_SEARCH:
			{
				s32Ret = PluginAutoGetProcess(pu32DataOk, pu32Process);
				stBuilderCtrl.m_u32Process = *pu32Process;
				break;
			}
			default:
			{
				PluginDvbLogcat("PluginGetProcess() - error search type %d\r\n", stBuilderCtrl.m_eSearchType);
				break;
			}

		}
		if(*pu32Process == SCAN_ALL_PROCESS && *pu32DataOk == 0)
			stBuilderCtrl.m_eStatus = BUILDER_PLUGIN_IDLE;
		s32Ret = 0;
	}
	PluginDvbLogcat("PluginGetProcess() - return, s32Ret = %d\r\n", s32Ret);
	
	return s32Ret;	
}

int PluginDataRecved(unsigned int hFilter, unsigned char* pu8Data, unsigned int u32Len)
{
	int s32Ret = -1;
	
	PluginDvbLogcat("PluginDataRecved() - entry, hFilter = %x, pu8Data = %p, u32Len = %d\r\n", hFilter, pu8Data, u32Len);
	PluginDvbLogcat("PluginDataRecved() - stBuilderCtrl.m_eStatus = %d\r\n", stBuilderCtrl.m_eStatus);
	if(stBuilderCtrl.m_eStatus == BUILDER_PLUGIN_INPROCESS)
	{			
		switch(stBuilderCtrl.m_eSearchType)
		{
			case BUILDER_SEARCH_MANUAL_SEARCH:
			{
				s32Ret = PluginManualSearchHandleDataRecved(pu8Data, hFilter);
				break;
			}
			case BUILDER_SEARCH_FULL_SEARCH:
			{
				s32Ret = PluginFullSearchHandleDataRecved(pu8Data, hFilter);
				break;
			}
			case BUILDER_SEARCH_AUTO_SEARCH:
			{
				s32Ret = PluginAutoSearchHandleDataRecved(pu8Data, hFilter);
				break;
			}
			default:
			{
				PluginDvbLogcat("PluginDataRecved() - while status is tuner lock\r\n");
				break;
			}
		}
	}
	else
	{
		PluginDvbLogcat("PluginDataRecved() - while status is not inprocess\r\n");
		s32Ret = 0;
	}
	PluginDvbLogcat("PluginDataRecved() - return, s32Ret = %d\r\n", s32Ret);
	return s32Ret;	
}

int PluginGetSearchData(builder_ts_t* pstTs, builder_service_t* pstServices, unsigned int* pu32ServiceCnt, builder_section_t** ppstBat, builder_section_t** ppstNit)
{
	int s32Ret = -1;
	builder_ts_t stTs;
	builder_service_t astServices[BUILDER_MAX_PROG_PER_TS];
	unsigned int u32ServiceCnt = 0;
	
	PluginDvbLogcat("PluginGetSearchData() - entry, pstTs = %p, pstServices = %p, pu32ServiceCnt = %p, pstBat = %p, pstNit = %p\r\n", pstTs, pstServices, pu32ServiceCnt, ppstBat, ppstNit);
	if(stBuilderCtrl.m_eStatus == BUILDER_PLUGIN_INPROCESS)
	{			
		switch(stBuilderCtrl.m_eSearchType)
		{
			case BUILDER_SEARCH_MANUAL_SEARCH:
			{
				s32Ret = PluginManualGetSearchData(pstTs, pstServices, pu32ServiceCnt, ppstBat, ppstNit);
				if(stBuilderCtrl.m_u32Process == 100)
					stBuilderCtrl.m_eStatus = BUILDER_PLUGIN_IDLE;
				break;
			}
			case BUILDER_SEARCH_FULL_SEARCH:
			{
				s32Ret = PluginFullGetSearchData(pstTs, pstServices, pu32ServiceCnt, ppstBat, ppstNit);
				if(stBuilderCtrl.m_u32Process == 100)
					stBuilderCtrl.m_eStatus = BUILDER_PLUGIN_IDLE;
				break;
			}
			case BUILDER_SEARCH_AUTO_SEARCH:
			{
				s32Ret = PluginAutoGetSearchData(pstTs, pstServices, pu32ServiceCnt, ppstBat, ppstNit);
				if(stBuilderCtrl.m_u32Process == 100)
					stBuilderCtrl.m_eStatus = BUILDER_PLUGIN_IDLE;
				break;
			}
			default:
			{
				PluginDvbLogcat("PluginDataRecved() - while status is tuner lock\r\n");
				break;
			}
		}
	}
	else
	{
		PluginDvbLogcat("PluginGetSearchData() - while status is not inprocess\r\n");
		s32Ret = 0;
	}
	PluginDvbLogcat("PluginGetSearchData() - return, s32Ret = %d\r\n", s32Ret);
	
	return s32Ret;	
}

int PluginSortByServiceId(builder_service_t* pstServices,  unsigned int* pu32ServiceCnt)
{
	unsigned int u32Index;
	int s32Ret = -1;
	unsigned int i;
	unsigned int j;
	builder_service_t curServiceData;
	builder_service_t tmpServiceData;
	unsigned short u16CurServiceid;
	unsigned short u16MinServiceid;
	
	PluginDvbLogcat("PluginSortByServiceId() - entry, pstServices = %d, pu32ServiceCnt = %p\r\n", pstServices, pu32ServiceCnt);
	if(pstServices && pu32ServiceCnt)
	{
		for(i=0; i<*pu32ServiceCnt;i++)
		{
			u16MinServiceid = 0;
			for(j=i; j<*pu32ServiceCnt; j++)
			{
				curServiceData = pstServices[j];
				u16CurServiceid = curServiceData.m_u16Serviceid;
				if(!u16MinServiceid || u16MinServiceid>u16CurServiceid)
				{
					u16MinServiceid = u16CurServiceid;
					u32Index = j;	
				}
			}
			if(u32Index != i)
			{
				tmpServiceData = pstServices[u32Index];
				pstServices[u32Index] = pstServices[i];
				pstServices[i] = tmpServiceData;
			}
		}
		s32Ret = 0;
	}
	PluginDvbLogcat("PluginSortByServiceId() - return, s32Ret = %d\r\n", s32Ret);
	return s32Ret;
}

int PluginSortForSameService(builder_service_t* pstServices,  unsigned int* pu32ServiceCnt)
{
	int s32Ret = -1;
	unsigned int i;
	builder_service_t *pstServices1 = NULL;
	builder_service_t *pstServices2 = NULL;
	builder_service_t tmp;
	int cnt1 = 0;
	int cnt2 = 0;
	PluginDvbLogcat("PluginSortForSameService() - entry, pstServices = %d, pu32ServiceCnt = %p\r\n", pstServices, pu32ServiceCnt);
	memset(&tmp,0,sizeof(builder_service_t));
	pstServices1 = (builder_service_t*)PluginDvbMemAlloc((*pu32ServiceCnt)*sizeof(builder_service_t));
	pstServices2 = (builder_service_t*)PluginDvbMemAlloc((*pu32ServiceCnt)*sizeof(builder_service_t));
	for(i=0;i<*pu32ServiceCnt;i++)
	{
		if(tmp.m_u16Orgnetid!=pstServices[i].m_u16Orgnetid || tmp.m_u16Tsid!=pstServices[i].m_u16Tsid || tmp.m_u16Serviceid!=pstServices[i].m_u16Serviceid || tmp.m_u32Freq!=pstServices[i].m_u32Freq)
		{
			pstServices1[cnt1++] = pstServices[i];
			tmp = pstServices[i];
		}
		else
		{
			pstServices2[cnt2++] = pstServices[i];
		}
	}

	PluginDvbLogcat("PluginSortForSameService total=%d,cnt1=%d,cnt2=%d\r\n",*pu32ServiceCnt, cnt1, cnt2);
	if(*pu32ServiceCnt == cnt1+cnt2)
	{
		for(i=0;i<cnt1;i++)
		{
			pstServices[i] = pstServices1[i];
		}

		for(i=cnt1;i<*pu32ServiceCnt;i++)
		{
			pstServices[i] = pstServices2[i-cnt1];
		}
	}
	PluginDvbMemFree(pstServices1);
	PluginDvbMemFree(pstServices2);
	PluginDvbLogcat("PluginSortForSameService() - return, s32Ret = %d\r\n", s32Ret);
	return s32Ret;
}

void PluginSwap(builder_service_t* a, builder_service_t* b)
{
	builder_service_t tmp;
	memcpy(&tmp, a, sizeof(builder_service_t));
	memcpy(a, b, sizeof(builder_service_t));
	memcpy(b, &tmp, sizeof(builder_service_t));
}

int PluginPartition(builder_service_t* pstServices, unsigned int low, unsigned int high)
{
	unsigned short KeyLcn = pstServices[low].m_u16Lcn;
	PluginDvbLogcat("PluginPartition() - entry, low=%d, high=%d\r\n", low,high);
	while (low < high) 
	{
		PluginDvbLogcat("PluginPartition() - , low=%d, high=%d, pstServices[high].m_u16Lcn=%d,pstServices[low].m_u16Lcn=%d\r\n", low,high, pstServices[high].m_u16Lcn,pstServices[low].m_u16Lcn);

		while (low < high && pstServices[high].m_u16Lcn >= KeyLcn) {
			--high;
		}
		PluginSwap(&pstServices[low],&pstServices[high]);

		while (low < high && pstServices[low].m_u16Lcn <= KeyLcn) {
			++low;
		}
		PluginSwap(&pstServices[low],&pstServices[high]);
	}

	return low;
}

int PluginQuickSortByLcn(builder_service_t* pstServices, unsigned int low, unsigned int high)
{
	PluginDvbLogcat("PluginQuickSortByLcn() - entry, low=%d, high=%d\r\n", low,high);
	
	if (low < high)
	{
		unsigned int PreLow = PluginPartition(pstServices,low, high);
		PluginDvbLogcat("PluginQuickSortByLcn() PreLow=%d\r\n", PreLow);
		//if (PreLow > 0) {
		if(PreLow > low+1)
			PluginQuickSortByLcn(pstServices, low, PreLow-1);

		if(PreLow+1 < high)
			PluginQuickSortByLcn(pstServices, PreLow+1, high);
		//}
	}
	
	return 0;
}

int PluginGetServiceOrder(builder_service_t* pstService, builder_section_t* pstBat)
{
	int s32Ret = -1;
	unsigned int u32Pos;
	builder_section_t* pstSection;
	unsigned int u32Num;
	unsigned int i;
	sipsi_dvb_stream_t stm;
	unsigned short u16TmpService;
	unsigned int u32LcnFounded = 0;

	pstSection = pstBat;
	while(pstSection && u32LcnFounded==0)
	{
		u32Num = SiPsiBatGetTSCount(pstSection->m_au8Section);
		for(i=0; i<u32Num; i++)
		{
			SiPsiBatGetTsStream(pstSection->m_au8Section, &stm, i);
			if(pstService->m_u16Tsid == stm.m_u16TransportStreamId)
			{
				unsigned int lcnCount=0; 
				unsigned int j=0; 
				unsigned int lcn;
				unsigned char* des;

				des = SiPsiFindDescriptor(stm.m_pu8Descriptors, stm.m_u16TransportDescriptorsLength, PLUGIN_TFDTMB_SERVICE_ORDER_TAG);
				if(des != NULL)
				{
					PluginDvbLogcat("PluginGetServiceOrder() -stm_tsid = 0x%x, stm_tslen = 0x%x\r\n", stm.m_u16TransportStreamId, stm.m_u16TransportDescriptorsLength);
					lcnCount=des[1]/5;
					for (j = 0; j < lcnCount; ++j)
					{
						u16TmpService = (des[2 + j * 5] << 8) | des[2 + j * 5 + 1];
						if(u16TmpService == pstService->m_u16Serviceid)
						{
							lcn=((des[2 + j * 5+3] &0x0f)<< 8) | des[2 + j * 5 + 4];
							PluginDvbLogcat("PluginGetServiceOrder() - find LCN descriptor!lcn = %d\r\n", lcn);
							pstService->m_u16Lcn = lcn;
							s32Ret = 0;
							u32LcnFounded = 1;
							break;
						}
					}

					if(u32LcnFounded == 1)
						break;
				}
			}
		}
		pstSection = pstSection->m_pstNext;
	}

	return s32Ret;
}

int PluginSetOrderNumInBat(builder_service_t* pstServices, unsigned int u32ServiceCnt, builder_section_t* pstBat)
{
	int s32Ret = -1;
	unsigned int i;

	for(i=0; i<u32ServiceCnt; i++)
	{
		s32Ret = PluginGetServiceOrder(&pstServices[i], pstBat);
	}
	
	return s32Ret;
}

int PluginProgSort(builder_ts_t* pstTsList, builder_service_t* pstServices, unsigned int* pu32ServiceCnt, builder_section_t* pstBat, builder_section_t* pstNit)
{
	int s32Ret = -1;
	char su8TmpArray[100];
	unsigned int i;
	
	PluginDvbLogcat("PluginProgSort() - entry, pstTsList = %d, pstServices = %p, pu32ServiceCnt = %p, pstBat = %p, pstNit = %p\r\n", pstTsList, pstServices, pu32ServiceCnt, pstBat, pstNit);
	if(pstBat == NULL)
	{
		s32Ret = 0;
		PluginSortByServiceId(pstServices, pu32ServiceCnt);
		PluginSortForSameService(pstServices, pu32ServiceCnt);
		for(i=0; i<*pu32ServiceCnt;i++)
		{
			memset(su8TmpArray, 0, sizeof(su8TmpArray));
			memcpy(su8TmpArray, pstServices[i].m_as8Name, pstServices[i].m_u16NameLen);
			PluginDvbConvertString(su8TmpArray, pstServices[i].m_u16NameLen, NULL);
			PluginDvbLogcat("PluginProgSort() - i[%d], Fre[%d], Tsid[%d], Sid[%d], Name[%s]\r\n", i, 
				pstServices[i].m_u32Freq, pstServices[i].m_u16Tsid, pstServices[i].m_u16Serviceid, su8TmpArray);
		}
	}
	else
	{
		s32Ret = PluginSetOrderNumInBat(pstServices, *pu32ServiceCnt, pstBat);
		s32Ret = PluginQuickSortByLcn(pstServices, 0, *pu32ServiceCnt-1);
		for(i=0; i<*pu32ServiceCnt;i++)
		{
			memset(su8TmpArray, 0, sizeof(su8TmpArray));
			memcpy(su8TmpArray, pstServices[i].m_as8Name, pstServices[i].m_u16NameLen);
			PluginDvbConvertString(su8TmpArray, pstServices[i].m_u16NameLen, NULL);
			PluginDvbLogcat("PluginProgSort() - i[%d], Fre[%d], Tsid[%d], Sid[%d], Lcn[%d], Name[%s]\r\n", i, 
				pstServices[i].m_u32Freq, pstServices[i].m_u16Tsid, pstServices[i].m_u16Serviceid, pstServices[i].m_u16Lcn, su8TmpArray);
		}
	}
	PluginDvbLogcat("PluginProgSort() - return, s32Ret = %d\r\n", s32Ret);
	
	return s32Ret;	
}


int PluginTick()
{
	int s32Ret = -1;
	
	PluginDvbLogcat("PluginTick() - entry stBuilderCtrl.m_eStatus=%d\r\n",stBuilderCtrl.m_eStatus);
	if(stBuilderCtrl.m_eStatus != BUILDER_PLUGIN_IDLE)
	{
		switch(stBuilderCtrl.m_eSearchType)
		{
			case BUILDER_SEARCH_MANUAL_SEARCH:
			{
				s32Ret = PluginManualSearchTick();
				break;
			}
			case BUILDER_SEARCH_FULL_SEARCH:
			{
				s32Ret = PluginFullSearchTick();
				break;
			}
			case BUILDER_SEARCH_AUTO_SEARCH:
			{
				s32Ret = PluginAutoSearchTick();
				break;
			}
			default:
			{
				PluginDvbLogcat("PluginTick() - error type\r\n");
				break;
			}
		}
	}
	else
	{
		PluginDvbLogcat("PluginTick() - receive error tick\r\n");
	}
	PluginDvbLogcat("PluginTick() - return, s32Ret = %d\r\n", s32Ret);
	return s32Ret;
}

int PluginInitialize (dvb_funcs_t* pstDvbFuncs,  plugin_funcs_t* pstPluginFuncs)
{
	int s32Ret = -1;

	memset(&stBuilderCtrl, 0, sizeof(stBuilderCtrl));
	if(pstDvbFuncs && pstPluginFuncs)
	{
		PluginDvbSetFun(pstDvbFuncs);
		pstPluginFuncs->m_u16Size = sizeof(plugin_funcs_t);
		pstPluginFuncs->m_u16Version = ICAST_PLUGIN_VERSION;
		pstPluginFuncs->m_pfPluginGetConfig = PluginGetConfig;
		pstPluginFuncs->m_pfPluginSearchStart = PluginSearchStart;
		pstPluginFuncs->m_pfPluginSeartchStop = PluginSearchStop;
		pstPluginFuncs->m_pfPluginLockFinish = PluginLockFinish;
		pstPluginFuncs->m_pfPluginGetProcss = PluginGetProcess;
		pstPluginFuncs->m_pfPluginDataRecved = PluginDataRecved;
		pstPluginFuncs->m_pfPluginGetSearchData = PluginGetSearchData;
		pstPluginFuncs->m_pfPluginProgSort = PluginProgSort;
		pstPluginFuncs->m_pfPluginMonitorStart = NULL;
		pstPluginFuncs->m_pfPluginMonitorStop = NULL;
		pstPluginFuncs->m_pfPluginTick = PluginTick;
	}

	return s32Ret;
}

int PluginDeinitialize()
{
	//memset(&stDvbFuncsList, 0, sizeof(stDvbFuncsList));
	return 0;
}

const char* PluginGetDescription()
{
	return "icastbuilder-plugin:common:8.0";
}

int PluginGetMagicId()
{
	return 0;
}

